<template>
  <div class="">
    <el-dialog :title="buDate.id==0?'添加':'修改'" :close-on-click-modal="false" v-model="dialogVisible"  :before-close="handleClose"
            style="padding: 50px; width: 600px;;">
            <el-form  ref="ruleFormRef" :rules="rules" label-width="auto">
                <el-form-item v-if="buDate.id==0 && buDate.pid" label="父楼栋名称"  prop="price">
                    <el-input disabled placeholder="" v-model="buDate.parentName"/>
                </el-form-item>
                <el-form-item label="名称" prop="name">
                    <el-input  placeholder=""  v-model="buDate.name"/>
                </el-form-item>
            </el-form>
            <el-button @click="dialogVisible = false">取消</el-button>
            <el-button type="primary" @click="submit">确认</el-button>
        </el-dialog>
  </div>
</template>

<script lang='ts' setup>
import { ref,watch,reactive } from "vue"
import { buildingdel,buildingadd } from '../service/building/building'
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
//添加页面显示
const dialogVisible = ref(true)
const emit = defineEmits(['close'])
interface RuleForm {
  name: string
}
const ruleFormRef = ref<FormInstance>()
const ruleForm = reactive<RuleForm>({
  name: '',
})

const rules = reactive<FormRules<RuleForm>>({
  name: [
    { required: true, message: '请输入姓名', trigger: 'blur' },
  ],
})

const porps= defineProps({
    buDate: {
        type: [Object],
        default: () => ({
            id: 0,
            name: '',
            parentName: '',
            pid: 0
        })
    },
})
const handleClose = () => {
    dialogVisible.value = false
    emit('close', [])
}

const submit = async ()=>{
    let res:any = await buildingadd(porps.buDate)
    if(res.errCode===10000){
    emit("close",true);
  }
}
</script>

<style  scoped>
</style>
